package com.jumi.microservice.controller.admin;

/**
 * @author Scw
 * @Date 2020-08-08 17:09
 */

import com.alibaba.excel.EasyExcel;
import com.jumi.microservice.common.base.BaseController;
import com.jumi.microservice.common.base.dto.ExportExcelCommonResponse;
import com.jumi.microservice.common.base.dto.ResponseResult;
import com.jumi.microservice.common.page.TableDataInfo;
import com.jumi.microservice.dto.reissue.*;
import com.jumi.microservice.service.admin.AdminReplacementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

/**
 * @author Scw
 * @Date 2020-08-05 11:38
 */
@Api(tags = {"后台售后管理--换货相关接口"})
@RestController
@RequestMapping("/admin/replacement")
public class AdminReplacementController extends BaseController {
    @Resource
    private AdminReplacementService adminReplacementService;

    @PostMapping("/exportExcel")
    @ApiOperation("导出excel")
    public void exportExcel(ExportReplacementListRequest request, HttpServletResponse response) throws IOException {
        ExportExcelCommonResponse<ExportReplacementListResponse> exportReplacementListResponseExportExcelCommonResponse = adminReplacementService.exportExcel(request);
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel");
        response.setCharacterEncoding("utf-8");
        response.setHeader("Content-disposition", "attachment;filename=" + exportReplacementListResponseExportExcelCommonResponse.getFileName());
        EasyExcel.write(response.getOutputStream(), ExportReplacementListResponse.class).sheet("sheet1").doWrite(exportReplacementListResponseExportExcelCommonResponse.getData());
    }

    @GetMapping("/replacementList")
    @ApiOperation("换货列表")
    TableDataInfo<ReissueListResponse> replacementList(ReissueListRequest reissueListRequest) {
        return adminReplacementService.replacementList(reissueListRequest);
    }

    @GetMapping("/replacementReason/dictionary")
    @ApiOperation("换货类型对照字典")
    public ResponseResult<Map<Integer, String>> getReplacementReason() {
        ResponseResult<Map<Integer, String>> result = new ResponseResult<>();
        result.setData(adminReplacementService.getReplacementReason());
        return result;
    }
}
